package psbc.daily.util;

import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jlwang
 * @version 1.0.0
 * @Description TODO
 * @ClassName SqlGenerator.java
 * @createTime 2021年08月12日 08:56:00
 */
public class SqlGenerator {
    public static void main(String[] args) throws Exception {
        //MBG执行过程中的警告信息
        List<String> warnings = new ArrayList<String>();

        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("./mybatis/mybatis-generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(in);

        DefaultShellCallback callback = new DefaultShellCallback(true);
        //创建MBG
        org.mybatis.generator.api.MyBatisGenerator mbg = new org.mybatis.generator.api.MyBatisGenerator(config, callback, warnings);
        mbg.generate(null);
        //输出警告信息
        for (String warn : warnings) {
            System.out.println(warn);
        }
    }
}
